#pragma once
#include<stdio.h>
#include<stdlib.h>

//定义线性表
//用于使用 连续的空间 顺序存储 数据
typedef struct List {
	int* data;
	int num;
	int length;
}List;

List* InitList(int length) {
	if (length <= 0)
		return NULL;

	List* list = (List*)malloc(sizeof(List));
	list->data = (int*)malloc(sizeof(int) * length);

	//初始化哨兵
	list->num = 0;

	list->length = length;
	return list;
}

void ListAdd(List* list, int data) {
	if (list->num == list->length) {
		printf("线性表长度已满\n");
		return;
	}

	list->data[list->num] = data;
	list->num += 1;
}

void ListPrint(List* list) {
	for (int i = 0; i < list->length; i++) {
		printf("%d -> ", list->data[i]);
	}
	printf("NULL\n");
}